﻿using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Modularity;
using Volo.Abp;
using Volo.Abp.Http.Client;
using Volo.Abp.Autofac;

namespace Himp.Platform.GraphQL
{
    [DependsOn(typeof(AbpHttpClientModule),
        typeof(AbpAutofacModule),
        typeof(PlatformApplicationContractsModule))]
    public class AppModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var configuration = context.Services.GetConfiguration();
            var hostingEnvironment = context.Services.GetHostingEnvironment();

            context.Services.AddControllers();
            context.Services.AddEndpointsApiExplorer();
            context.Services.AddSwaggerGen();
            context.Services.AddGraphQLServer().AddQueryType<GraphQLQuery>();

            //context.Services.AddHttpClientProxies(
            //    typeof(PlatformApplicationContractsModule).Assembly);
        }

        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var env = context.GetEnvironment();

            // Configure the HTTP request pipeline.
            if (env.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseAuthorization();
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseConfiguredEndpoints(endpoints =>
            {
                endpoints.MapGraphQL();
            });
        }
    }
}
